package patterns.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lenovo on 2016/11/24 0024.
 * 演示使用标准模式，或者称为过滤器模式
 */
public class FilterPatternDemo {
    public static void main(String[] args) {
        List<Person> people = new ArrayList<>();

        people.add(new Person("Robert", "man", "single"));
        people.add(new Person("John", "man", "married"));
        people.add(new Person("Laura", "woman", "married"));
        people.add(new Person("Diana", "woman", "single"));
        people.add(new Person("Mike", "man", "single"));
        people.add(new Person("Bobby", "man", "single"));

        IFilter man = new FilterMan();
        IFilter woman = new FilterWoman();
        IFilter single = new FilterSingle();
        IFilter singleMan = new FilterAnd(single, man);
        IFilter singleOrMan = new FilterOr(single, man);

        System.out.println("Man:");
        printPersons(people, man);

        System.out.println("Woman:");
        printPersons(people, woman);

        System.out.println("SingleMan:");
        printPersons(people, singleMan);

        System.out.println("Single Or Man :");
        printPersons(people, singleOrMan);
    }

    //显示筛选人群信息
    private static void printPersons(List<Person> people, IFilter man) {
        for (Person person : man.matchCriteria(people)) {
            System.out.printf("Person:Name=%s,Gender=%s,Marital Status=%s", person.getName(), person.getGender(), person.getMaritalStatus());
        }
        System.out.println();
    }
}
